﻿<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MSH.Common.Business" assembly="Common">

<class name="User" table="USER">

  <id name="ID">

      <generator class="native">
        <param name="sequence">SeqUserID</param>
      </generator>

  </id>

  <property name="Username">
    <column name="Username" length="30" not-null="true" unique="true"/> <!-- Unique constraint zorgt in Firebird al voor een index. -->
  </property>

  <property name="Password">
    <column name="PASSWORD" length="32" not-null="true"/>
  </property>

  <property name="Status">
    <column name="Status" length="30" not-null="false"  />
  </property>

  <property name="Activated">
    <column name="Activated" not-null="false" default="0"/>
  </property>

  <property name="LastSeenTimestamp">
    <column name="LastSeenTimestamp" not-null="false" />
  </property>

  <property name="RegisteredTimestamp">
    <column name="RegisteredTimestamp" not-null="false" />
  </property>

  <property name="ActivationRequestCount">
    <column name="ActivationRequestCount" not-null="false" />
  </property>

  <many-to-one name="UserProfile"
      unique="true"
      column="UserProfile" cascade="all" fetch="join"/>

  <many-to-one name="UserSettings"
    unique="true"
    column="UserSettings" cascade="all" fetch="join"/>

  <many-to-one name="UserActivation"
    unique="true"
    column="UserActivation" cascade="all" fetch="join"/>

  <set name="UserLocations" cascade="all" order-by="ID">
    <key column="USER"/>
    <one-to-many class="UserLocation"/>
  </set>

  <many-to-one name="LastUserLocation"
  unique="true"
  column="LastUserLocation" cascade="all" fetch="join"/>

  <set name="UserFriends" cascade="all-delete-orphan" order-by="ID">
    <key column="ParentUser"/>
    <one-to-many class="UserFriend"/>
  </set>

  <set name="ChatMessages" cascade="all-delete-orphan" order-by="ID">
    <key column="USER"/>
    <one-to-many class="ChatMessage"/>
  </set>

  <set name="UserSocialNetworkAccounts" cascade="all-delete-orphan">
    <key column="ParentUser"/>
    <one-to-many class="UserSocialNetworkAccount"/>
  </set>

  <set name="UserSocialNetworkProfileData" cascade="all-delete-orphan">
    <key column="ParentUser"/>
    <one-to-many class="UserSocialNetworkProfileData"/>
  </set>

</class>

  <database-object>
    <create>
      CREATE INDEX IDXUSERSEARCH1 ON "USER" COMPUTED BY (UPPER (USERNAME));
    </create>
    <drop>
      DROP INDEX IDXUSERSEARCH1;
    </drop>
    <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>

  </database-object>

</hibernate-mapping>

